import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    children:[
      {
        path:"/",
        redirect:"/users"
      },{
        path:"/users",
        component:()=>import('../components/Users.vue')
      }, {
        path:"/roles",
        component:()=>import('../components/Juese.vue')
      },{
        path:"/rights",
        component:()=>import('../components/Power.vue')
      },{
        path:"/goods",
        component:()=>import('../components/Goods.vue')
      },{
        path:"/params",
        component:()=>import('../components/Params.vue')
      },{
        path:"/categories",
        component:()=>import('../components/Categories.vue')
      },{
        path:"/orders",
        component:()=>import('../components/Orders.vue')
      },
    ]
  },
  {
    path: '/Login',
    name: 'Login',
    component: () => import('../views/Login.vue')
  }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to,from,next)=>{
  var token = sessionStorage.getItem("token");
  if (!token) {
    if (to.path != '/Login') {
      next("/Login");
    }else{
      next()
    }
  }else{
    next()
  }
})

export default router
